﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using SystemHYS.API.Application.command.ProductionOrdersCommand;
using SystemHYS.Domian;
using SystemHYS.Infrstructre.Interface;

namespace SystemHYS.API.Application.commandler.ProductionOrdersCommandler
{
    public class ProductionOrdersShowCommandler:IRequestHandler<ProductionOrdersShowCommand,List<ProductionOrders>>
    {
        IProductionOrdersRepository OrdersRepository;

        public ProductionOrdersShowCommandler(IProductionOrdersRepository ordersRepository)
        {
            OrdersRepository = ordersRepository;
        }

        public async Task<List<ProductionOrders>> Handle(ProductionOrdersShowCommand request, CancellationToken cancellationToken)
        {
            var list = from a in await OrdersRepository.GetAllAsnc() where a.IsDel==false select a;
            if (request.OrderNumber != null)
            {
                list=list.Where(x=>x.OrderNumber.Contains(request.OrderNumber));
            }
            if (request.State!=null)
            {
                list = list.Where(x => x.State==request.State);
            }
            if (request.AddTime!=null)
            {
                list=list.Where(x=>x.AddTime==request.AddTime);
            }
            return list.ToList();
        }
    }
}
